RAIS  3.2
C:/Projekte/RAIS/common/DynamicMask.cs
Go to the documentation of this file.
00001 
00028 using System;
00029 using System.Collections.Generic;
00030 using System.Data;
00031 using System.Text;
00032 using RAIS.Common.TableManagement;
00033 
00034 using DynamicMaskTypes = System.Collections.Generic.Dictionary<RAIS.Common.DynamicMaskManagement.DynamicMask.DynamicMaskType, RAIS.Common.DynamicMaskManagement.DynamicMask.DynamicMaskTypeData>;
00035 
00036 namespace RAIS.Common.DynamicMaskManagement
00037 {
00041         public class DynamicMask :DBObject
00042         {
00043                 //*********************************************************************
00044                 #region Enums
00045                 public enum DynamicMaskType
00046                 {
00047                         SingleRowMaskWithList = 0,
00048                         ListWithFilter,
00049                         SingleRowMask,
00050                         ReportMask
00051                 }
00052                 #endregion
00053                 //*********************************************************************
00054                 #region Fields
00055                 static DynamicMaskTypes dynamicMaskTypesDictionary;
00056 
00057                 int order;
00058                 DynamicMaskType type;
00059                 Table table;
00060                 string queryName;
00061                 string widths;
00062                 string reference;
00063                 string controlName;
00064                 string maskName;
00065                 List<ConsistencyCheck> consistencyChecks;
00066                 string grouping;
00067                 string footer;
00068                 Dictionary<string, DynamicMaskFilter> filters = new Dictionary<string,DynamicMaskFilter>();
00069                 #endregion
00070                 //*********************************************************************
00071                 #region Properties
00072 
00075                 static public DynamicMaskTypes DynamicMaskTypesDictionary
00076                 {
00077                         get { return dynamicMaskTypesDictionary; }
00078                         set { dynamicMaskTypesDictionary = value; }
00079                 }
00080 
00084                 public int Order
00085                 {
00086                         get { return this.order; }
00087                         set { this.order = value; }
00088                 }
00092                 public DynamicMaskType Type
00093                 {
00094                         get { return this.type; }
00095             set { this.type = value; }
00096                 }
00100         public DynamicMaskTypeData TypeData
00101         {
00102             get { return DynamicMaskTypesDictionary[this.Type]; }
00103         }
00107                 public Table Table
00108                 {
00109                         get { return this.table; }
00110                         set { this.table = value; }
00111                 }
00115                 public string QueryName
00116                 {
00117                         get { return this.queryName; }
00118                 }
00122                 public string Grouping
00123                 {
00124                         get { return this.grouping; }
00125                         set { this.grouping = value; }
00126                 }
00130                 public string Widths
00131                 {
00132                         get { return this.widths; }
00133                         set { this.widths = value; }
00134                 }
00138                 public string Footer
00139                 {
00140                         get { return this.footer; }
00141                         set { this.footer = value; }
00142                 }
00146                 public string Reference
00147                 {
00148                         get { return this.reference; }
00149                         set { this.reference = value; }
00150                 }
00154                 public string ControlName
00155                 {
00156                         get { return this.controlName; }
00157                         set { this.controlName = value; }
00158                 }
00162                 public string MaskName
00163                 {
00164                         get { return this.maskName; }
00165                         set { this.maskName = value; }
00166                 }
00170                 public bool IsFacilityMask
00171                 {
00172                         get 
00173                         { 
00174                                 return (this.type == DynamicMaskType.ListWithFilter 
00175                                         && this.Table.Name == Constants.FACILITY_TABLE_NAME); 
00176                         }
00177                 }
00181                 public bool IsDepartmentMask
00182                 {
00183                         get 
00184                         { 
00185                                 return (this.type == DynamicMaskType.ListWithFilter 
00186                                         && this.Table.Name == Constants.DEPARTMENT_TABLE_NAME); 
00187                         }
00188                 }
00192                 public List<ConsistencyCheck> ConsistencyChecks
00193                 {
00194                         get { return consistencyChecks; }
00195                         set { consistencyChecks = value; }
00196                 }
00200                 public string AuthorizationType
00201                 {
00202                         get 
00203                         {
00204                                 return (this.Table.Name == RAIS.Common.Constants.AUTHORIZATION_TABLE_NAME)
00205                                         ? this.maskName
00206                                         : string.Empty;
00207                         }
00208                 }
00212                 public Dictionary<string, DynamicMaskFilter> Filters
00213                 {
00214                         get { return this.filters; }
00215                         set { this.filters = value; }
00216                 }
00220                 public string FiltersXml
00221                 {
00222                         get
00223                         {
00224                                 StringBuilder xmlString = new StringBuilder("'<Filters>");
00225                                 if (this.filters != null && this.filters.Count != 0)
00226                                 {
00227                                         foreach (KeyValuePair<string, DynamicMaskFilter> kvp in this.filters)
00228                                         {
00229                                                 DynamicMaskFilter filter = kvp.Value;
00230                                                 xmlString.AppendFormat("<Filter Name=\"{0}\" TableID=\"{1}\" QueryName=\"{2}\" Order=\"{3}\" VisibleOnForm=\"{4}\" UseInQuery=\"{5}\" OrderInQuery=\"{6}\" >"
00231                                                         , filter.Name
00232                                                         , (filter.Table != null) ? filter.Table.ID : 0
00233                                                         , filter.QueryName
00234                                                         , filter.Order
00235                                                         , (filter.VisibleOnForm) ? 1.ToString() : 0.ToString()
00236                                                         , (filter.UseInQuery) ? 1.ToString() : 0.ToString()
00237                                                         , filter.OrderInQuery);
00238 
00239                                                 if (filter.ParentFilters != null && filter.ParentFilters.Count != 0)
00240                                                 { 
00241                                                         int i = 1;
00242                                                         foreach (KeyValuePair<string, DynamicMaskFilter> kvpp in filter.ParentFilters)
00243                                                         {
00244                                                                 DynamicMaskFilter parameter = kvpp.Value;
00245                                                                 xmlString.AppendFormat("<FilterParameter Name=\"{0}\" Order=\"{1}\" />"
00246                                                                         , parameter.Name
00247                                                                         , i++);
00248                                                         }
00249                                                 }
00250 
00251                                                 xmlString.AppendFormat("</Filter>");
00252                                         }
00253                                 }
00254 
00255                                 xmlString.Append("</Filters>'");
00256 
00257                                 return xmlString.ToString();
00258                         }
00259                 }
00260 
00261                 #endregion
00262                 //*********************************************************************
00263                 #region Constructors
00264                 public DynamicMask()
00265                 { }
00270         public DynamicMask(IDataRecord record)
00271                 {
00272                         this.id = (int)record["PK Dynamic Mask ID"];
00273                         this.order = (int)record["Order"];
00274                         this.name = record["Dynamic Mask Name"].ToString();
00275                         this.type = (DynamicMaskType)Enum.Parse(typeof(DynamicMaskType), record["Dynamic Mask Type Name"].ToString());
00276                         if (!(record["FK Table ID"] is DBNull))
00277                         {
00278                                 this.table = new Table();
00279                                 this.table.ID = (int)record["FK Table ID"];
00280                         }
00281                         this.queryName = record["Query Name"].ToString();
00282                         this.grouping = record["Grouping"].ToString();
00283                         this.widths = record["Widths"].ToString();
00284                         this.footer = record["Footer"].ToString();
00285                         this.reference = record["Reference"].ToString();
00286                         this.maskName = record["Mask Name"].ToString();
00287                 }
00288                 #endregion
00289                 //*********************************************************************
00290                 #region Static methods
00291 
00292 
00293 
00294 
00295 
00296                 static public DynamicMaskType? GetTypeByVisibleName(string visibleName)
00297                 {
00298                         DynamicMaskType? type = null;
00299                         foreach (KeyValuePair<DynamicMaskType, DynamicMaskTypeData> kvp in dynamicMaskTypesDictionary)
00300                         {
00301                                 if (kvp.Value.VisibleName == visibleName)
00302                                 {
00303                                         type = kvp.Key;
00304                                         break;
00305                                 }
00306                         }
00307                         return type;
00308                 }
00309                 #endregion Static methods
00310                 //*********************************************************************
00311                 #region Public methods
00312 
00313 
00314 
00315 
00316                 public void SetNewQuery(Query query)
00317                 {
00318                         this.Filters.Clear();
00319                         if (query == null)
00320                         {
00321                                 this.queryName = string.Empty;
00322                         }
00323                         else
00324                         {
00325                                 this.queryName = query.Name;
00326                                 if (query.QueryParameters != null)
00327                                         CreateDynamicMaskFiltersByQuery(query, null, true);
00328 
00329                                 // Set UserID as the last parameter in list
00330                                 bool shift = false;
00331                                 foreach (KeyValuePair<string, DynamicMaskFilter> kvp in this.Filters)
00332                                 {
00333                                         DynamicMaskFilter filter = kvp.Value;
00334                                         if (shift)
00335                                         {
00336                                                 filter.Order--;
00337                                         }
00338                                         else
00339                                         {
00340                                                 if (filter.Name == RAIS.Common.Constants.USER_PARAMETER_NAME)
00341                                                 {
00342                                                         shift = true;
00343                                                         filter.Order = this.Filters.Count;
00344                                                 }
00345                                         }
00346 
00347                                 }
00348                         }
00349                 }
00350                 #endregion
00351                 //*********************************************************************
00352                 #region Private methods
00353                 void CreateDynamicMaskFiltersByQuery(Query query, DynamicMaskFilter childFilter, bool useInQuery)
00354                 {
00355                         int orderInQuery = 1;
00356                         foreach (KeyValuePair<string, QueryParameter> kvp in query.QueryParameters)
00357                         {
00358                                 QueryParameter queryParameter = kvp.Value;
00359 
00360                                 // Filter name
00361                                 string filterName = string.Empty;
00362                                 if (queryParameter.Type == QueryParameter.QueryParameterType.UserID)
00363                                 {
00364                                         filterName = Constants.USER_PARAMETER_NAME;
00365                                 }
00366                                 else if (queryParameter.Type == QueryParameter.QueryParameterType.PreselectedFacility)
00367                                 {
00368                                         filterName = Constants.FACILITY_PARAMETER_NAME;
00369                                 }
00370                                 else if (queryParameter.Type == QueryParameter.QueryParameterType.PreselectedDepartment)
00371                                 {
00372                                         filterName = Constants.DEPARTMENT_PARAMETER_NAME;
00373                                 }
00374                                 else
00375                                 {
00376                                         if (queryParameter.Type == QueryParameter.QueryParameterType.DatesRangeStartDate
00377                                                 || queryParameter.Type == QueryParameter.QueryParameterType.DatesRangeEndDate)
00378                                         {
00379                                                 filterName = Constants.DATES_RANGE_FILTER_NAME;
00380                                         }
00381                                         else
00382                                         {
00383                                                 filterName = queryParameter.VisibleName;
00384                                         }
00385                                 }
00386 
00387                                 // Filter key
00388                                 string filterKey = string.Empty;
00389                                 if (queryParameter.Type == QueryParameter.QueryParameterType.UserID
00390                                         || queryParameter.Type == QueryParameter.QueryParameterType.PreselectedFacility
00391                                         || queryParameter.Type == QueryParameter.QueryParameterType.PreselectedDepartment
00392                                         || queryParameter.Type == QueryParameter.QueryParameterType.DatesRangeStartDate
00393                                         || queryParameter.Type == QueryParameter.QueryParameterType.DatesRangeEndDate)
00394                                 {
00395                                         filterKey = filterName;
00396                                 }
00397                                 else
00398                                 {
00399                                         filterKey = queryParameter.DBObjectName;
00400                                 }
00401 
00402                                 // Create or find existing filter
00403                                 DynamicMaskFilter dynamicMaskFilter = new DynamicMaskFilter();
00404                                 if (!this.filters.ContainsKey(filterKey))
00405                                 {
00406                                         dynamicMaskFilter.Name = filterName;
00407                                         dynamicMaskFilter.QueryName = (queryParameter.RelatedQuery == null) ? string.Empty : queryParameter.RelatedQuery.Name;
00408                                         dynamicMaskFilter.VisibleOnForm = (queryParameter.Type != QueryParameter.QueryParameterType.UserID
00409                                                 && queryParameter.Type != QueryParameter.QueryParameterType.PreselectedFacility
00410                                                 && queryParameter.Type != QueryParameter.QueryParameterType.PreselectedDepartment);
00411                                         dynamicMaskFilter.Table = queryParameter.Table;
00412                                         dynamicMaskFilter.Order = filters.Count + 1;
00413                                         dynamicMaskFilter.UseInQuery = useInQuery;
00414 
00415                                         this.filters.Add(filterKey, dynamicMaskFilter);
00416 
00417                                         if (queryParameter.RelatedQuery != null
00418                                                 && queryParameter.RelatedQuery.QueryParameters != null)
00419                                         {
00420                                                 CreateDynamicMaskFiltersByQuery(queryParameter.RelatedQuery, dynamicMaskFilter, false);
00421                                         }
00422                                 }
00423                                 else
00424                                 {
00425                                         dynamicMaskFilter = filters[filterKey];
00426                                         if (useInQuery)
00427                                                 dynamicMaskFilter.UseInQuery = useInQuery;
00428                                 }
00429 
00430                                 if (useInQuery)
00431                                         dynamicMaskFilter.OrderInQuery = orderInQuery++;
00432                                 
00433                                 // Add parent filter
00434                                 if (childFilter != null)
00435                                         childFilter.ParentFilters.Add(filterKey, dynamicMaskFilter);
00436                         }
00437                 }
00438                 #endregion
00439                 //*********************************************************************
00440                 #region Nested Classes
00441 
00442 
00443 
00444                 public class DynamicMaskTypeData: DBTypeObject
00445                 {
00446                         //*********************************************************************
00447                         #region Fields
00448                         string reference;
00449                         #endregion
00450                         //*********************************************************************
00451                         #region Properties
00452 
00453 
00454 
00455                         public DynamicMaskType Type
00456                         {
00457                                 get { return (DynamicMaskType)Enum.Parse(typeof(DynamicMaskType), this.name); }
00458                         }
00462             public string Reference
00463                         {
00464                                 get { return this.reference; }
00465                         }
00466                         #endregion
00467                         //*********************************************************************
00468                         #region Constructors
00469                         public DynamicMaskTypeData()
00470                         {}
00475                         public DynamicMaskTypeData(IDataRecord record)
00476                         {
00477                                 this.id = (int)record["PK Dynamic Mask Type ID"];
00478                                 this.name = record["Dynamic Mask Type Name"].ToString();
00479                                 this.visibleName = record["Dynamic Mask Type Visible Name"].ToString();
00480                                 this.reference = record["Reference"].ToString();
00481                         }
00482                         #endregion
00483                 }
00484                 #endregion
00485         }
00486 }